<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('计划列表')"/>
    <style>
        .fixed-table-toolbar {
            display: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <input id="status" name="status" value="2,3" type="hidden">
                        <input id="planType" name="planType" value="2" type="hidden">
                        <li>
                            计划编号：<input type="text" name="planCode"/>
                        </li>
                        <li>
                            作物名称：<input type="text" name="cropNameCn"/>
                        </li>
                        <li>
                            作物品种：<input type="text" name="cropVarietiesCn"/>
                        </li>
                        <li class="select-time">
                            <label>播种/定植： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginPlanTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endPlanTime]"/>
                        </li>
                        <li>
                            生产班组：<input type="text" name="teamCn"/>
                        </li>

                        <li>
                            计划制定人：<input type="text" name="createBy"/>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <!--<div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncPlan:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:ncPlan:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:ncPlan:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:ncPlan:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncPlan:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncPlan:remove')}]];
    var prefix = ctx + "system/ncPlan2";

    var landType = [[${@dict.getType('landType')}]];
    $(function () {
        var options = {
            url: prefix + "/list?planType=1&status=2,3,4",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "计划",
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'planId',
                    title: '计划id',
                    visible: false
                },
                {
                    field: 'planCode',
                    title: '计划编号',
                    sortable: true
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                },
                {
                    field: 'landType',
                    title: '设施类型',
                    sortable: false,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(landType, value);
                    }
                },
                {
                    field: 'teamCn',
                    title: '生产班组',
                    sortable: true
                },
                {
                    field: 'planTime',
                    title: '播种/定植时间',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return dateFtt(value);
                    }

                },
                {
                    field: 'chaci',
                    title: '茬次',
                    sortable: true
                },
                {
                    field: 'area',
                    title: '单茬面积(亩)',
                    sortable: true
                },
                {
                    field: 'jian',
                    title: '间数',
                    sortable: true
                },
                {
                    field: 'sumArea',
                    title: '总面积(亩)',
                    sortable: true
                },
                {
                    field: 'cycleArea',
                    title: '循环面积(亩)',
                    sortable: true
                },
                {
                    field: 'cycleDays',
                    title: '循环天数',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '计划制定时间',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'createBy',
                    title: '计划制定人'
                },
                {
                    field: 'standard.standardName',
                    title: '标准名称',
                }, {
                    field: 'status',
                    title: '状态',

                    formatter: function (value, row, index) {
                        /*状态 1:待生成订单 2：待执行 3.在执行 4.已完成*/
                        if (value == 1) {
                            return '<span class="badge badge-warning">待生成订单</span>'
                        } else if (value == 2) {
                            return '<span class="badge badge-info">待执行</span>'
                        } else if (value == 3) {
                            return '<span class="badge badge-primary">在执行</span>'
                        } else if (value == 4) {
                            return '<span class="badge badge-success">已完成</span>'
                        } else {
                            return "--";
                        }
                    }
                },
                /*{
                    field: 'remark',
                    title: '备注',
                },*/

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (!row.standardId) {
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editStandard(\'' + row.planId + '\')"><i class="fa fa-warning"></i>标准</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.planId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.planId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if (row.status == 4 && row.standardId) {
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="createStandard(\'' + row.planId + '\')"><i class="fa fa-remove"></i>生成标准</a>');

                        }

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function editStandard(plandId) {
        var url = ctx + 'system/ncPlan/editStandard/' + plandId
        $.modal.open("修改标准", url);
    }

    function createStandard(plandId) {
        var url = ctx + 'system/ncStandard/createStandardByPlan';
        myPost(url, {plandId: plandId},
            function (data) {
                if (data.code == 0) {
                    $.modal.msgSuccess("创建成功")
                } else {
                    $.modal.msgSuccess(data.msg);
                }
                window.location.reload();
            }, function (e) {
                $.modal.msgSuccess("创建失败!");
            });


    }
    setTitle("所有计划",true)
</script>
</body>
</html>